package br.roove.bomotivo.ui;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.FragmentManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;

import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;

public class CustomPhotoAdapter extends BaseAdapter{
	
	LayoutInflater mInflater = null;
	
	
	public CustomPhotoAdapter(Context context, ArrayList<String> images) {
		super();
		this.context = context;
		this.imagesToLoad = images;
		mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	
	
	public CustomPhotoAdapter() {
		super();
		// TODO Auto-generated constructor stub
	}



	String URL;
	ProgressDialog pd;
	Context context;
	ArrayList<String> imagesToLoad;
	String [] images;

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return imagesToLoad.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	public class ViewHolder{
		ImageView imagem;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		//mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = convertView;
		ViewHolder holder;
		//final View v2 = convertView;
		//final int index = position;
		if (view == null){
			view = mInflater.inflate(R.layout.griditem, parent, false);
			holder = new ViewHolder();
			holder.imagem = (ImageView)view.findViewById(R.id.image_grid);
			//holder.imagem.setImageResource(R.drawable.bomotivo_logo);
			UrlImageViewHelper uhelper = new UrlImageViewHelper();
			uhelper.setUrlDrawable(holder.imagem, imagesToLoad.get(position),android.R.drawable.dialog_frame);
			view.setTag(holder);
		}else{
			holder = (ViewHolder)view.getTag();
			holder = new ViewHolder();
			holder.imagem = (ImageView)view.findViewById(R.id.image_grid);
			UrlImageViewHelper uhelper = new UrlImageViewHelper();
			uhelper.setUrlDrawable(holder.imagem, imagesToLoad.get(position),android.R.drawable.dialog_frame);
		}
				
		return view;
	}
	
	

}
